package com.huawei.appgallery.share.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.ui.framework.activity.AbstractBaseActivity;
import com.huawei.appgallery.share.api.ShareBean;
import com.huawei.appgallery.share.items.ShareBottomSheet;
import com.huawei.appgallery.share.protocol.ShareDialogActivityProtocol;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import o.ayw;
import o.cku;
import o.cwj.c;
import o.cwj.d;
import o.cwj.i;
import o.cwr;
import o.cxg;
import o.cxi;
import o.cxk;
import o.djl;
import o.eqx;
import o.eqz;
import o.erq;
import o.eua;
import o.evd;
import o.ll;

public class ShareDialogActivity extends AbstractBaseActivity<ShareDialogActivityProtocol> implements cxi, OnDismissListener {
    private boolean ʻॱ;
    private boolean ʾ = true;
    private ShareBottomSheet ˈ;
    private djl ˊॱ = null;
    private LinearLayout ˋॱ;
    private ShareBean ˏॱ;
    private Map<String, List<View>> ͺ = new HashMap();
    private List<cxg> ॱˊ = new ArrayList();
    private LayoutInflater ॱˋ;
    private boolean ॱˎ = false;
    private Bitmap ᐝॱ;

    class AnonymousClass3 implements OnDismissListener {
        final /* synthetic */ ShareDialogActivity ˊ;

        public void onDismiss(DialogInterface dialogInterface) {
            if (!eua.ˏ().ˏ("share_permission_note_key", false)) {
                this.ˊ.ˋˊ();
            }
        }
    }

    class e implements eqz {
        final /* synthetic */ ShareDialogActivity ˋ;

        private e(ShareDialogActivity shareDialogActivity) {
            this.ˋ = shareDialogActivity;
        }

        public void ॱ(Bitmap bitmap) {
            if (this.ˋ.isDestroyed() || this.ˋ.isFinishing()) {
                cwr.ॱ.ˋ("ShareDialogActivity", "activity is destroy.");
                return;
            }
            if (bitmap != null) {
                this.ˋ.ᐝॱ = bitmap.copy(Config.ARGB_8888, true);
                cwr.ॱ.ˋ("ShareDialogActivity", "get net bitmap success!");
            } else {
                this.ˋ.ᐝॱ = null;
                cwr.ॱ.ˋ("ShareDialogActivity", "get net bitmap failed!");
            }
            this.ˋ.ʻॱ = true;
            for (cxg ॱ : this.ˋ.ॱˊ) {
                ॱ.ॱ();
            }
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().requestFeature(1);
        evd.ˏ(getWindow());
        setContentView(d.ˎ);
        this.ˈ = (ShareBottomSheet) findViewById(c.ˎ);
        ShareDialogActivityProtocol shareDialogActivityProtocol = (ShareDialogActivityProtocol) ʾ();
        if (shareDialogActivityProtocol == null || shareDialogActivityProtocol.ˏ() == null) {
            cwr.ॱ.ˊ("ShareDialogActivity", "can not find any param.");
            finish();
            return;
        }
        this.ॱˋ = LayoutInflater.from(this);
        View inflate = this.ॱˋ.inflate(d.ˋ, null);
        this.ˋॱ = (LinearLayout) inflate.findViewById(c.ˊ);
        this.ˏॱ = shareDialogActivityProtocol.ˏ();
        ʼॱ();
        ˊˋ();
        if (this.ॱˊ.isEmpty()) {
            cwr.ॱ.ˊ("ShareDialogActivity", "can not find any share method.");
            finish();
            return;
        }
        ˉ();
        if (this.ॱˊ.size() > 1 || ((cxg) this.ॱˊ.get(0)).ˋ()) {
            ayw.ˋ(this, inflate, null, false);
            this.ˈ.ˋ(inflate);
        } else {
            int childCount = this.ˋॱ.getChildCount();
            for (int i = 0; i < childCount; i++) {
                View childAt = this.ˋॱ.getChildAt(i);
                if (childAt != null && childAt.getVisibility() == 0 && childAt.isEnabled() && childAt.isClickable()) {
                    childAt.performClick();
                }
            }
        }
        eqx.ॱ((Context) this, this.ˏॱ.ˋ(), new e());
        Intent intent = new Intent("hiappbase.share.activity.onCreate");
        intent.putExtra("share.appidtype", this.ˏॱ.ʽ());
        intent.putExtra("share.fromwhere", this.ˏॱ.ʼ());
        intent.putExtra("shareurl", this.ˏॱ.ʻ());
        ll.ˏ(getApplicationContext()).ˋ(intent);
    }

    private void ʼॱ() {
        if (evd.ˎ() && this.ˏॱ.ˎ() != 0) {
            if (erq.ˏ(this.ˏॱ.ˎ())) {
                evd.ˊ(getWindow(), 1);
            } else {
                evd.ˊ(getWindow(), 0);
            }
        }
    }

    public void onDestroy() {
        for (cxg ˎ : this.ॱˊ) {
            ˎ.ˎ(this.ˏॱ);
        }
        this.ͺ.clear();
        this.ॱˊ.clear();
        if (this.ˊॱ != null && this.ˊॱ.isShowing()) {
            this.ˊॱ.dismiss();
        }
        cku.ˎ((Context) this, "ShareDialog");
        super.onDestroy();
    }

    private void ˊˋ() {
        for (Class newInstance : cxk.ˎ()) {
            cxg o_cxg;
            try {
                o_cxg = (cxg) newInstance.newInstance();
            } catch (InstantiationException e) {
                cwr.ॱ.ˊ("ShareDialogActivity", "get ShareMessageCenter handler falid" + e.getMessage());
                o_cxg = null;
            } catch (IllegalAccessException e2) {
                cwr.ॱ.ˊ("ShareDialogActivity", "get ShareMessageCenter handler falid" + e2.getMessage());
                o_cxg = null;
            }
            if (!(o_cxg == null || o_cxg.ˊ(this.ˏॱ))) {
                this.ॱˊ.add(o_cxg);
            }
        }
    }

    private void ˉ() {
        for (cxg ˏ : this.ॱˊ) {
            if (ˏ.ˏ(this, this.ˋॱ, this.ॱˋ, !this.ॱˎ, this.ˏॱ)) {
                this.ॱˎ = true;
            }
        }
    }

    private void ˋˊ() {
        finish();
    }

    public Context ᐝ() {
        return this;
    }

    public void ˋ(@NonNull String str, @NonNull View view) {
        if (TextUtils.isEmpty(str)) {
            cwr.ॱ.ˊ("ShareDialogActivity", "can not keep empty pkg.");
            return;
        }
        List list = (List) this.ͺ.get(str);
        if (list == null) {
            list = new ArrayList();
        }
        list.add(view);
        this.ͺ.put(str, list);
    }

    @NonNull
    public List<View> ˊ(@NonNull String str) {
        if (str == null) {
            return new ArrayList(0);
        }
        if ("".equals(str)) {
            List<View> arrayList = new ArrayList();
            for (List addAll : this.ͺ.values()) {
                arrayList.addAll(addAll);
            }
            return arrayList;
        }
        List<View> list = (List) this.ͺ.get(str);
        if (list == null) {
            return new ArrayList(0);
        }
        return list;
    }

    public List<String> ॱˊ() {
        List<String> arrayList = new ArrayList();
        for (cxg ˎ : this.ॱˊ) {
            arrayList.add(ˎ.ˎ());
        }
        return arrayList;
    }

    public void ͺ() {
        if (this.ˊॱ == null) {
            this.ˊॱ = new djl(this);
            this.ˊॱ.ˋ(getString(i.ʼ));
            this.ˊॱ.setOnDismissListener(this);
            this.ˊॱ.setCancelable(false);
            this.ˊॱ.show();
            return;
        }
        this.ˊॱ.show();
    }

    public void onDismiss(DialogInterface dialogInterface) {
        for (cxg ˏ : this.ॱˊ) {
            ˏ.ˏ();
        }
    }

    public cxi.d ᐝॱ() {
        cxi.d dVar = new cxi.d();
        dVar.ˊ = this.ʻॱ;
        dVar.ˏ = this.ᐝॱ;
        return dVar;
    }

    public void finish() {
        this.ˈ.ˊ();
        super.finish();
        overridePendingTransition(0, o.cwj.e.ˎ);
    }

    public boolean ॱᐝ() {
        return false;
    }
}
